package ru.papergames.web.services;

import org.hibernate.Criteria;
import org.hibernate.Session;
import ru.common.hibernate.HibernateAction;
import ru.papergames.common.form.BattleServerCredentialsForm;
import ru.papergames.common.model.BattleServerCredentials;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Alexander Troshanin
 */
public class GetBattleServers implements HibernateAction<List<BattleServerCredentialsForm>> {

    @Override
    public List<BattleServerCredentialsForm> execute(Session session) {
        Criteria c = session.createCriteria(BattleServerCredentials.class);
        List<BattleServerCredentials> lst = c.list();
        List<BattleServerCredentialsForm> result = new ArrayList<BattleServerCredentialsForm>(lst.size());
        for (BattleServerCredentials cred : lst) {
            result.add(new BattleServerCredentialsForm(cred));
        }
        return result;
    }
}
